home *** CD-ROM | disk | FTP | other *** search
- /*
- Mean.c
- Computes mean (and optionally the standard deviation) of an array of samples.
-
- HISTORY:
- 9/16/90 dgp wrote it.
- */
- #include "VideoToolbox.h"
- #include <math.h>
-
- double Mean(double x[],long n,double *sdPtr)
- {
- register double s,mean,xx;
- register long i;
-
- s=0.0;
- for(i=0;i<n;i++) s+=x[i];
- mean=s/n;
- if(sdPtr!=NULL){
- s=0.0;
- for(i=0;i<n;i++){
- xx=x[i];
- s+=xx*xx;
- }
- *sdPtr=sqrt((s-n*mean*mean)/(n-1));
- }
- return mean;
- }
-